package com.xhj.springbootproject.controller;

import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author ：Xionghaijun
 * @date ：Created in 2019/7/1 2:03 PM
 * @description：
 */
@Controller
public class IndexController {

    private final Logger logger = LoggerFactory.getLogger(IndexController.class);

    private final String PREFIX = "pages/";

    /**
     * 欢迎页
     * @return
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model) throws Exception {
        logger.info("访问首页");
//        int i = 1 / 0;
//        System.out.println("客户访问");
        model.addAttribute("name", "hello springBoot");
        return "index";
    }

    /**
     * 登陆页
     * @return
     */
    @RequestMapping("/login")
    public String loginPage() {
        return PREFIX + "login";
    }

    @RequestMapping(value = "/error403Page")
    public String error403Page(Model model) {
        model.addAttribute("code", "403");
        model.addAttribute("msg", "您无权限访问该页面，请联系管理员开通");
        return PREFIX + "/error/" + "403";
    }

    @RequestMapping(value = "/error404Page")
    public String error404Page(Model model) {
        model.addAttribute("code", 404);
        model.addAttribute("msg", "页面输错啦，请联系管理员处理");
        return PREFIX + "/error/" + "404";
    }


    @RequestMapping(value = "/level/{path}", method = RequestMethod.GET)
    public String level(@PathVariable("path")String path) {
        return PREFIX + "level/"+path;
    }
    /**
     * level1页面映射
     * @param path
     * @return
     */
    @RequestMapping(value = "/level1/{path}", method = RequestMethod.GET)
    public String level1(@PathVariable("path")String path) {
        return PREFIX + "level1/"+path;
    }

    /**
     * level2页面映射
     * @param path
     * @return
     */
    @RequestMapping(value = "/level2/{path}", method = RequestMethod.GET)
    public String level2(@PathVariable("path")String path) {
        return PREFIX + "level2/"+path;
    }

    /**
     * level3页面映射
     * @param path
     * @return
     */
    @RequestMapping(value = "/level3/{path}", method = RequestMethod.GET)
    public String level3(@PathVariable("path")String path) {
        return PREFIX + "level3/"+path;
    }

}
